package com.yssw.customer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yssw.common.annotation.Anonymous;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yssw.common.annotation.Log;
import com.yssw.common.core.controller.BaseController;
import com.yssw.common.core.domain.AjaxResult;
import com.yssw.common.enums.BusinessType;
import com.yssw.customer.domain.CustomerTable;
import com.yssw.customer.service.ICustomerTableService;
import com.yssw.common.utils.poi.ExcelUtil;
import com.yssw.common.core.page.TableDataInfo;

/**
 * 客户申报管理Controller
 *
 * @author yssw
 * @date 2023-03-28
 */
@Anonymous
@RestController
@RequestMapping("/customer/customer")
public class CustomerTableController extends BaseController {
    @Autowired
    private ICustomerTableService customerTableService;

    /**
     * 查询客户申报管理列表
     */
//    @PreAuthorize("@ss.hasPermi('customer:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerTable customerTable) {
        startPage();
        List<CustomerTable> list = customerTableService.selectCustomerTableList(customerTable);
        return getDataTable(list);
    }

    /**
     * 导出客户申报管理列表
     */
//    @PreAuthorize("@ss.hasPermi('customer:customer:export')")
    @Log(title = "客户申报管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerTable customerTable) {
        List<CustomerTable> list = customerTableService.selectCustomerTableList(customerTable);
        ExcelUtil<CustomerTable> util = new ExcelUtil<CustomerTable>(CustomerTable.class);
        util.exportExcel(response, list, "客户申报管理数据");
    }

    /**
     * 获取客户申报管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('customer:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(customerTableService.selectCustomerTableById(id));
    }

    /**
     * 新增客户申报管理
     */
//    @PreAuthorize("@ss.hasPermi('customer:customer:add')")
    @Log(title = "客户申报管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerTable customerTable) {
        return toAjax(customerTableService.insertCustomerTable(customerTable));
    }

    /**
     * 修改客户申报管理
     */
//    @PreAuthorize("@ss.hasPermi('customer:customer:edit')")
    @Log(title = "客户申报管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerTable customerTable) {
        return toAjax(customerTableService.updateCustomerTable(customerTable));
    }

    /**
     * 删除客户申报管理
     */
//    @PreAuthorize("@ss.hasPermi('customer:customer:remove')")
    @Log(title = "客户申报管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(customerTableService.deleteCustomerTableByIds(ids));
    }

    /**
     * 获取未读客户申报数量
     */
//    @PreAuthorize("@ss.hasPermi('customer:customer:remove')")
    @GetMapping("/getMsg")
    public AjaxResult getMsg() {
        return success(customerTableService.getMsg());
    }

    /**
     * 清空未读客户申报数量
     */
//    @PreAuthorize("@ss.hasPermi('customer:customer:remove')")
    @GetMapping("/clearMsg")
    public AjaxResult clearMsg() {
        return success(customerTableService.clearMsg());
    }
}
